package com.becca.cake.controller.system;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.becca.cake.core.common.BaseAction;
import com.becca.cake.service.system.IUserLoadMenuService;
import com.becca.cake.util.PMSConstants;
import com.becca.cake.util.StringUtil;

/**
 * 登录后加载主菜单
 * @author hejinguo
 * @version $Id: UserLoadMenuAction.java, v 0.1 2013-12-2 下午12:48:44
 */
@Controller
@RequestMapping("/systemMenu")
public class UserLoadMenuAction extends BaseAction {
    private final static Log     logger = LogFactory.getLog(UserLoadMenuAction.class);
    @Autowired
    private IUserLoadMenuService iUserLoadMenuService;

    /**
     * 加载主页面顶级菜单
     * @author hejinguo
     * @return
     */
    @RequestMapping(value = "/selectTopMenu", method = RequestMethod.POST)
    public @ResponseBody
    String selectTopMenu() {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("parentId", Long.valueOf(PMSConstants.FUNCTION_ROOT));
        map.put("priAdminDO", this.getUserSeesion());
        try {
            return this.iUserLoadMenuService.selectTopMenu(map);
        } catch (Exception e) {
            logger.error("加载头部功能菜单失败!", e);
        }
        return null;
    }

    /**
     * 加载主页面左侧功能菜单信息
     * @author hejinguo
     * @param request
     * @param id
     * @return
     */
    @RequestMapping(value = "/selectLeftMenu", method = RequestMethod.POST)
    public @ResponseBody
    String selectLeftMenu(HttpServletRequest request,
                          @RequestParam(value = "id", required = false) String id) {
        if (StringUtil.isNotEmpty(id)) {
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("id", id);
            map.put("adminId", this.getUserSeesion().getId());
            try {
                return this.iUserLoadMenuService.selectLeftMenu(map);
            } catch (Exception e) {
                logger.error("加载左侧功能菜单树失败!", e);
            }
        }
        return null;
    }
}
